package dto

import (
	"syuee.com/iShot/model"
)
//返回用户信息
type UserDto struct {
	Id       int    `json:"id"`
	Rid      int    `json:"rid"`
	Username string `json:"username"`
	Mobile   string `json:"mobile"`
	Email    string `json:"email"`
	Mg_state bool    `json:"mg_state"`
}

func (con UserDto) ToUserDtoAll(user []model.I_manager) []UserDto {
	user_dto := []UserDto{}
	for _, value := range user {
		user_dto = append(user_dto, con.ToUserDto(value))
	}
	return user_dto
}
func (con UserDto) ToUserDto(user model.I_manager) UserDto {
	i := false
	if user.Mg_state==1{
		i=true
	}
	return UserDto{
		Id:       user.Mg_id,
		Rid:      user.Role_id,
		Username: user.Mg_name,
		Mobile:   user.Mg_mobile,
		Email:    user.Mg_email,
		Mg_state :i,
	}
}
//返回带token的用户信息
type UserDtoToken struct {
	UserDto
	Token string `json:"token,omitempty"`
}

func (con UserDtoToken) ToUserDto(user model.I_manager, token string) UserDtoToken {

	return UserDtoToken{
		UserDto: UserDto{
			Id:       user.Mg_id,
			Rid:      user.Role_id,
			Username: user.Mg_name,
			Mobile:   user.Mg_mobile,
			Email:    user.Mg_email,
		},
		Token: string(token),
	}
}
